/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/29/11
 * Time: 6:02 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class TaskF extends Thread {
    public TaskF() {
        try {
            this.input = new BufferedReader(new FileReader("input.txt"));
            this.output = new PrintWriter("output.txt");
            this.setPriority(Thread.MAX_PRIORITY);
        } catch (Throwable e) {

        }
    }

    static final long gcd(long a, long b) {
        return b != 0 ? gcd(b, a % b) : a;
    }

    private void solve() throws Throwable {
        long x = nextLong(), b = nextLong(), g;
        int before = 0;
        while ((g = gcd(x, b)) > 1) {
            ++before;
            x /= g;
        }
        long phi = x, X = x;
        if (phi < 4) {
            --phi;
        }
        for (long i = 2; i * i <= x; ++i) {
            if (x % i == 0) {
                while (x % i == 0) {
                    x /= i;
                }
                phi -= phi / i;
            }
        }
        if (x > 1) {
            phi -= phi / x;
        }
        long period = phi;
        for (long div = 1; div * div <= phi; ++div) {
            if (phi % div != 0) {
                continue;
            }
            long[] candidates = {div, phi / div};
            for (long current : candidates) {
                if (BigInteger.valueOf(b).modPow(BigInteger.valueOf(current), BigInteger.valueOf(X)).longValue() == 1) {
                    period = Math.min(period, current);
                }
            }
        }
        output.println(before + " " + period);
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

    public static void main(String[] args) {
        new TaskF().start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}
